//获取应用实例
const app = getApp()

//获取cookie
module.exports.getCoockie = function(url, callback) {
  var that = this//不要漏了这句，很重要

  wx.showLoading('Logining')

  wx.request({
    url: url,
    header: {
      'Content-Type': 'application/json'
    },

    success: res => {
      //请求成功后，进行一些函数操作
      if (res.data == null) {
        showToast('net work error');
      }
      callback.success(res);
    },

    fail: function() {
      showToast('Login failed, please try again')
      callback.fail();
    },
    
    complete: function() {
      wx.hideLoading()
    }
  })
}

//登陆
module.exports.login = function login(url, callback) {
  wx.request({
    url: url,
    header: {
      'Content-Type': 'application/json'
    },
    success: res => {
      callback.success(res);
    },
    fail: function() {
      callback.fail();
    }
  })
}

function showToast(title) {
  wx.showToast({
    title: title,
  })
}

function showLoading(title) {
  wx.showLoading({
    title: title,
    mask: false,
  })
}